package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domin.Teacher;

public class TeacherService {
    private static TeacherDao teacherDao = new TeacherDao();

    //添加老师
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTtudent(teacher);
    }

    //查看老师
    public Teacher[] findAllTeacher() {
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null){
                return teachers;
            }
        }
        return null;
    }

    //删除老师
    public void deleteTeacher(String sid) {
        teacherDao.deleteTeacher(sid);
    }

    //修改老师
    public void updateTeacher(String sid, Teacher teacher) {
        teacherDao.updateTeacher(sid,teacher);
    }

    //判断工号是否存在
    public boolean isExists(String sid) {
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null&&teacher.getSid().equals(sid)){
                return true;
            }
        }
        return false;
    }
}
